package mx.itesm.minAFN;

import java.util.ArrayList;
import java.util.Dictionary;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;



public class AFNState {
	private String _stateName;
	private Hashtable<String, ArrayList<String>> _transitions;
	private AFNStateType _type;
	private Boolean _lock = false;
	
	
	
	public Boolean getLock() {
		return _lock;
	}




	public void setLock(Boolean lock) {
		_lock = lock;
	}




	public String getStateName() {
		return _stateName;
	}




	public void setStateName(String stateName) {
		_stateName = stateName;
	}




	public Hashtable<String, ArrayList<String>> getTransitions() {
		return _transitions;
	}




	public void setTransitions(Hashtable<String, ArrayList<String>> transitions) {
		_transitions = transitions;
	}




	public AFNStateType getType() {
		return _type;
	}




	public void setType(AFNStateType type) {
		_type = type;
	}


	public AFNState(String name, AFNStateType type){
		this._stateName = name;
		this._type = type;
		this._transitions = new Hashtable<String, ArrayList<String>>();
	}
	
	public void addTransition(String c, ArrayList<String> dest){
		this._transitions.put(c, dest);
	}
	
	public void addTransition(String c, HashSet dest){
		ArrayList<String> list = new ArrayList<String>();
		for (Object object : dest) {
			list.add((String)object);
		}
		this.addTransition(c, list);
	}
	
	public ArrayList<String> getTransition(String c){
		return this._transitions.get(c);
	}


	public boolean equalsTypes(AFNState state){
		if(this._type != state.getType()){
			if(((this._type == AFNStateType.FINAL || this._type == AFNStateType.START_FINAL) && (state.getType() == AFNStateType.NORMAL || state.getType() == AFNStateType.START))
					|| ((this._type == AFNStateType.NORMAL || this._type == AFNStateType.START) && (state.getType() == AFNStateType.FINAL || state.getType() == AFNStateType.START_FINAL))	
					){
				return false;
			}
		}
		
		return true;
	}

	@Override
	protected AFNState clone() {
		// TODO Auto-generated method stub
		return new AFNState(_stateName, _type);
	}




	@Override
	public String toString() {
		return getStateName()+"("+getType()+")"+" "+getTransitions();
	}
	
	
	
}
